package udpmessaging;

import com.messaging.UdpMq;
import com.messaging.events.MessageReceiveEvent;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;

/**
 * @author sad
 */
public class TestUdpServer {

    public static void main(String[] args) throws Exception {
        UdpMq mq = new UdpMq(9874);
        final int[] array = new int[10000];
        mq.setMessageReceiveEvent(new MessageReceiveEvent() {

            @Override
            public void messageReceive(byte[] buffer, InetAddress sender, int port) throws UnsupportedEncodingException {
                int v = UdpMq.copyIntFromArray(buffer, 0);
                if (array[v] != 0) {
                    System.err.println("err:" + v);
                }

                array[v] = 5;
            }
        });

        mq.start();
        Thread.sleep(20000);
        for (int i = 0; i < 10000; i++) {
            if (array[i] == 0) {
                System.out.println(i);
            }
        }
        System.out.println("End");
    }
}
